﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;

public partial class Admin_adm_stats_images : System.Web.UI.Page
{
    public string ckid = "";

    public string VisiblePanel(string pnlVal)
    {
        string pnl = Request.QueryString["DocType"] == null ? "1" : Request.QueryString["DocType"];
        string res = "myHideAvatar";
        //switch (pnl)
        //{
        //    case"1":
        //        res = "myShowAvatar";
        //        break;
        //    case"4":
        //        res = "myShowAvatar";
        //        break;
        //    case"5":
        //        res = "myShowAvatar";
        //        break;

        //}
        if (pnl == pnlVal) { res = "myShowAvatar"; }
        return res;
    }

    public string ClassNameAvatar()
    {
        string DocType = Request.QueryString["DocType"] == null ? "" : Request.QueryString["DocType"];
        string res = "myHideAvatar";
        dtlImage.RepeatColumns = 2;
        switch (DocType)
        {
            case "1":
                break;
            case "5":
                res = "myShowAvatar";
                dtlImage.RepeatColumns = 5;
                break;
            default:
                break;
        }
        return res;
    }

    public string ClassNameNoneAvatar()
    {
        string DocType = Request.QueryString["DocType"] == null ? "" : Request.QueryString["DocType"];
        string res = "myShowAvatar";
        dtlImage.RepeatColumns = 5;
        switch (DocType)
        {

            case "1":
                break;
            case "5":
                res = "myHideAvatar";
                dtlImage.RepeatColumns = 2;
                break;
            default:
                
                break;
        }
        return res;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            for (DateTime dt = Convert.ToDateTime("01/01/2006"); dt <= DateTime.Now.AddYears(3); dt = dt.AddYears(1))
            {
                ddlPeriodYear.Items.Add(new ListItem(dt.Year.ToString(), dt.Year.ToString()));
                ddlFromYear.Items.Add(new ListItem(dt.Year.ToString(), dt.Year.ToString()));
            }

            a_Session ss = null;
            a_User usr = null;
            a_UserType usrType = null;
            //if (SessionManager.IsLogged)
            //{
            ss = a_SessionService.Geta_Session(SessionManager.GetCookie());
            ckid = ss.SessionID;
            usr = a_UserService.Geta_User(ss.CookieID);
            usrType = a_UserTypeService.Geta_UserType(usr.UserTypeID);

            ltrWellcome.Text ="Hi "+ usr.Firstname+" "+ usr.Lastname;

            ddlFromYear.Items.Insert(0, new ListItem("", ""));
            ddlFromYear.SelectedIndex = 1;
            ddlPeriodYear.SelectedValue = DateTime.Now.Year.ToString();
            ddlFromMonth.SelectedIndex = 2;

            loadData();
        }
    }

    public void loadData()
    {
        string dateTo = "";
        string dateFrom = "";
        int page = Convert.ToInt32(Request.QueryString["p"] == null ? "1" : Request.QueryString["p"]);
              
        string doctype = Request.QueryString["DocType"] == null ? "3" : Request.QueryString["DocType"];
        if (doctype == "5")
        {
            dtlImage.RepeatColumns = 5;
        }
        else { dtlImage.RepeatColumns = 2; }

        switch (doctype)
        {
            case"1":
                break;
            case"4":
                break;
            case"5":
                break;
            default:
                
                break;
        }

        dateTo = ddlPeriodYear.SelectedValue + "-" + ddlPeriodMonth.SelectedValue+"-01";// +"-01 23:59:59";
        if (ddlFromMonth.SelectedValue != "" &&  ddlFromYear.SelectedValue != "")
        {
            dateFrom = ddlFromYear.SelectedValue + "-" + ddlFromMonth.SelectedValue+"-01";// +"-28 00:00:00";
        }

        DataSet ds = a_ArticleService.a_StatReport_Images(dateTo, dateFrom,
               ddlSortBy.SelectedValue, ddlOrderBy.SelectedValue,
               txtSelectTop.Text, doctype, page, 50, 6);

        if (ds.Tables.Count < 2)
        {
            ltrCurrentPage.Text = "No item found";
        }
        else
        {
            DataTable dtbPaging = ds.Tables[0];

            dtlImage.DataSource = ds.Tables[1];
            dtlImage.DataBind();

          //  GridView1.DataSource = ds.Tables[1];
          //  GridView1.DataBind();
          ltrPaging.Text= CommonFunc.QueryPaging(page, Convert.ToInt32(dtbPaging.Rows[0]["TotalRecords"])/20+1, 6);
          ltrPaging.Visible = false;
          AdminPaging1.Total = Convert.ToInt32(dtbPaging.Rows[0]["TotalRecords"]);
        }

    }

    public string DetailImage(object aID, object kTitle, object fYear, object imgNo)
    {
        string res = "";
        res = kTitle.ToString().ToLower().Trim().Replace(" ", "-");
        res = FOConstants.Dir_ImgArticle + res + "-" + fYear.ToString() + "-d" + aID.ToString() + imgNo.ToString() + ".jpg";
        return res;
    }
    protected void btnGo_Click(object sender, EventArgs e)
    {
        loadData();
    }
/*
    public static string Paging(int totalRecord, int recPerPage, int pageSet)
    {
        string currentUrl = HttpContext.Current.Request.Url.ToString();

        int currentPage = HttpContext.Current.Request.QueryString["p"] == null ? 1 : Convert.ToInt32(HttpContext.Current.Request.QueryString["p"]);
        int prePage = currentPage == 1 ? 1 : currentPage - 1;
        int nextPage = currentPage + 1;
        int lastPage = totalRecord / recPerPage + 1;

        string[] parseUrl = currentUrl.Split('?');

        currentUrl = parseUrl[0];
        string currentParam = "";

        if (parseUrl.Length > 1)
        {
            string[] urlParam = { };
            urlParam = parseUrl[1].Split('&');
            for (int i = 0; i < urlParam.Length; i++)
            {
                if (urlParam[i].IndexOf("p=") < 0) currentParam += urlParam[i] + "&";
            }
            currentParam = currentParam.Trim('&');
        }

        string paging = "<table class='p3 fr'><tr>";
        paging += "<td class='next-pre'><a href='" + currentUrl + "?p=1&" + currentParam + "'><img height='17' width='28' alt='thoi trang' src='../images/nav_previousset_off.gif'/></a></td>";
        paging += "<td class='next-pre'><a href='" + currentUrl + "?p=" + prePage.ToString() + "&" + currentParam + "'><img height='17' width='28' alt='thoi trang' src='../images/nav_previouspage_off.gif'/></a></td>";

        if (currentPage > pageSet)
        {
        }
        else
        {
            for (int i = 1; i < currentPage; i++)
            {
                paging += "<td class='go'><a href='" + currentUrl + "?p=" + i.ToString() + "&" + currentParam + "'>" + i.ToString() + "</a></td>";
            }
        }

        for (int i = currentPage; i < currentPage + pageSet; i++)
        {
            if (i == currentPage)
                paging += "<td class='current'><a href='" + currentUrl + "?p=" + i.ToString() + "&" + currentParam + "'>" + i.ToString() + "</a></td>";
            else
                paging += "<td class='go'><a href='" + currentUrl + "?p=" + i.ToString() + "&" + currentParam + "'>" + i.ToString() + "</a></td>";
        }

        paging += "<td class='next-pre'><a href='" + currentUrl + "?p=" + nextPage.ToString() + "&" + currentParam + "'><img height='17' width='28' alt='thoi trang' src='../images/nav_nextpage_on.gif'/></a></td>";
        paging += "<td class='next-pre'><a href='" + currentUrl + "?p=" + lastPage.ToString() + "&" + currentParam + "'><img height='17' width='28' alt='thoi trang' src='../images/nav_nextset_off.gif'/></a></td>";
        paging += "</tr></table>";

        return paging;
    }
*/
   
}
